package com.clstu.socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketTCP01Client {
    public static void main(String[] args) throws IOException {
        //连接本机的9999端口，如果连接成功，就返回Socket对象
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        System.out.println("客户端 socket 返回 ======"+socket.getClass());

        OutputStream outputStream = socket.getOutputStream();//得到输出流对象，可以传输数据了
        outputStream.write("hello , server ".getBytes());//传输数据

        outputStream.close();
        socket.close();//关闭连接，释放资源
        System.out.println("客户端已经退出======");
    }
}
